//
//  HomeViewController.m
//  TenThousand
//
//  Created by baixue on 16/6/6.
//  Copyright © 2016年 baixue. All rights reserved.
//

#import "HomeViewController.h"
#import "LoginTableViewCell.h"
#import "PurchaseTableViewCell.h"
#import "HeaderTableViewCell.h"
#import "FooterTableViewCell.h"
#import "RegularCell.h"
#import "CurrentViewController.h"
#import "WelcomeLoginViewController.h"
#import "LoginViewController.h"//登录注册页面
#import "RecommendViewController.h"//推荐有礼
#import "InvestmentViewController.h"
#import "ZLScrolling.h"
#import "WalletViewController.h"//萬钱宝
#import "BorrowGetHome.h"//
#import "WantBorrowViewController.h"
#import "MyPayViewController.h"
#import "DailyCheckFirstView.h"
#import "DailyCheckSecondView.h"
#import "DailyCheckThirdView.h"
#import "MyInvestViewController.h"



@interface HomeViewController ()<UITableViewDataSource,UITableViewDelegate,UIScrollViewDelegate,ZLScrollingDelegate, UIAlertViewDelegate>
{
    ZLScrolling *_zl;
    NSString *_SaleNumber;
    NSString *_SumNumber;
    NSString *_State;
    NSInteger _aititude;
    
}

@property (nonatomic, strong) UIButton *backView;
@property (nonatomic, strong) UIWindow *window;
@property (nonatomic, strong) NSMutableArray *imageArray;
@property (nonatomic, strong) NSMutableArray *homeArr;
@property (nonatomic, strong) NSMutableArray *moneyArr;

@property (nonatomic, strong) DailyCheckFirstView *dailYCheckFirstV;
@property (nonatomic, strong) DailyCheckSecondView *dailYCheckSecondV;
@property (nonatomic, strong) DailyCheckThirdView *dailYCheckThirdV;

@property (nonatomic, assign) NSInteger dailyNum;
@property (nonatomic, assign) NSInteger remainsNum;

@property (nonatomic, copy)void(^overRequestBlock)();

@end
#define StringArray @[@"",@"",@"",@""]
#define TitleArray @[@"每日签到",@"推荐有礼",@"我要投资",@"我要借款"]
#define TitleLable @[@"严格甄选优质生产",@"六层风控安全保障",@"贴心服务便携流程"]
#define lsh
@implementation HomeViewController

- (NSMutableArray *)imageArray {
    if (!_imageArray) {
        _imageArray = [NSMutableArray array];
    }
    return _imageArray;
}

- (NSMutableArray *)homeArr{
    if (!_homeArr) {
        _homeArr = [NSMutableArray array];
    }
    return _homeArr;
}

- (NSMutableArray *)moneyArr {
    if (!_moneyArr) {
        _moneyArr = [NSMutableArray array];
    }
    return _moneyArr;
}

- (DailyCheckFirstView *)dailYCheckFirstV {
    if (!_dailYCheckFirstV) {
        _dailYCheckFirstV = [[DailyCheckFirstView alloc] initWithFrame:CGRectMake(0, 0, 230, 210)];
    }
    if ([_State isEqualToString:@"1"]) {
        [_dailYCheckFirstV.sureBtn setBackgroundImage:[UIImage imageNamed:@"classify4-1"] forState:UIControlStateNormal];
        _dailYCheckFirstV.sureBtn.enabled = NO;
        [_dailYCheckFirstV.sureBtn setTitle:@"" forState:UIControlStateNormal];
        return _dailYCheckFirstV;
    }else{
    
    [_dailYCheckFirstV.sureBtn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    return _dailYCheckFirstV;
    }
}

- (DailyCheckSecondView *)dailYCheckSecondV {
    if (!_dailYCheckSecondV) {
        _dailYCheckSecondV = [[DailyCheckSecondView alloc] initWithFrame:CGRectMake(0, 0, 230, 210)];
    }
    _dailYCheckSecondV.dailyNumLabel.text = [NSString stringWithFormat:@"%@", _SumNumber];
    _dailYCheckSecondV.remainsNumLabel.text = [NSString stringWithFormat:@"%@", _SaleNumber];
    return _dailYCheckSecondV;
}

- (DailyCheckThirdView *)dailYCheckThirdV {
    if (!_dailYCheckThirdV) {
        _dailYCheckThirdV = [[DailyCheckThirdView alloc] initWithFrame:CGRectMake(0, 0, 230, 210)];
    }
    [_dailYCheckThirdV.checkBtn addTarget:self action:@selector(checkBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    return _dailYCheckThirdV;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.mytableView];

    
    self.dailyNum = 0;
    self.remainsNum = 7;
    [self refresh];

//    [self getSearchImage];
    
    [self getHomeAmount];//获取累计金额
    
   
}


#pragma mark -------------tableview开始-------------
- (UITableView *)mytableView{
    if (!_mytableView) {
        _mytableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, Screen_Width, Screen_Height) style:UITableViewStyleGrouped];
        _mytableView.dataSource = self;
        _mytableView.delegate = self;
        _mytableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _mytableView.showsVerticalScrollIndicator = NO;
        
    }
    return _mytableView;
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
//代理方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.homeArr.count+3;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 0) {
        HeaderTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellID"];
        if (cell == nil) {
            cell = [[HeaderTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellID"];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backView.layer.shadowColor = [UIColor lightGrayColor].CGColor;
        cell.backView.layer.shadowOffset = CGSizeMake(0.5, 0.5);
        cell.backView.layer.shadowOpacity = YES;
        cell.Clicked = ^(NSInteger tag){
            switch (tag)  {
                    
                    //我要投资
                case 1002:
                {
                    // self.tabBarController.selectedIndex = 1;
                    if ([[NSUserDefaults standardUserDefaults] objectForKey:@"LoginId"]) {
                        WantBorrowViewController *wantBorrowVC = [[WantBorrowViewController alloc] init];
                        wantBorrowVC.hidesBottomBarWhenPushed = YES;
                        [self.navigationController pushViewController:wantBorrowVC animated:NO];
                    } else {
                        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"未登录，请先登录" delegate: self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
                        alert.tag = 10000;
                        [alert show];
                    }
                    
                }
                    break;
                    //推荐有礼
                case 1001:
                {
                    self.tabBarController.selectedIndex = 1;
                }
                    break;
                    
                    //我要签到
                case 1000:
                {
                    [self getNumber];
                    
                }
                    break;
                case 1003:
                {

                    
                    //我要充值
                    if ([[NSUserDefaults standardUserDefaults] objectForKey:@"LoginId"]) {
                        MyPayViewController *myPayView =[[MyPayViewController alloc] init];
                        [self setHidesBottomBarWhenPushed:YES];
                        [self.navigationController pushViewController:myPayView animated:YES];
                        [self setHidesBottomBarWhenPushed:NO];
                    } else {
                        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"未登录，请先登录" delegate: self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
                        alert.tag = 10000;
                        [alert show];
                    }
                    
                }
                    break;
                    
                default:
                    break;
            }
        };
        return cell;
    }else if (indexPath.row == 1) {
        LoginTableViewCell *loginCell = [tableView dequeueReusableCellWithIdentifier:@"LOGINCELL"];
        if (!loginCell) {
            loginCell = [[[NSBundle mainBundle] loadNibNamed:@"LoginTableViewCell" owner:nil options:nil] lastObject];
        }
        
        if (self.moneyArr.count) {
            BorrowGetHome *model = [self.moneyArr firstObject];
            loginCell.TenderHomeAmount.text = [NSString stringWithFormat:@"%.2f",[model.TenderHomeAmount floatValue ]];
        }
        
        loginCell.selectionStyle = UITableViewCellSelectionStyleNone;
        loginCell.backView.layer.shadowColor = [UIColor lightGrayColor].CGColor;
        loginCell.backView.layer.shadowOffset = CGSizeMake(0.5, 0.5);
        loginCell.backView.layer.shadowOpacity = YES;
        
       
        loginCell.backgroundColor = [UIColor colorWithRed:0.96 green:0.96 blue:0.96 alpha:1.00];
    
        
        if ([[NSUserDefaults standardUserDefaults] objectForKey:@"LoginId"]) {
            [loginCell.login setTitle:@"立即投资" forState:UIControlStateNormal];
            loginCell.Clicked = ^(){
               self.tabBarController.selectedIndex = 1;

            };
        }else{ [loginCell.login setTitle:@"注册／登录" forState:UIControlStateNormal];
            //跳转登录注册页面
            loginCell.Clicked = ^(){
                NSLog(@"dianji");
                WelcomeLoginViewController *loginView = [[WelcomeLoginViewController alloc] init];
                loginView.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:loginView animated:NO];
            };
        
    }
        return loginCell;
    }else if(indexPath.row == self.homeArr.count+2){
        FooterTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FOOTERTABLEVIEWCELL"];
        if (cell == nil) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"FooterTableViewCell" owner:nil options:nil] lastObject];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else {
        PurchaseTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PURCHASETABLECELL"];
        if (cell == nil) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"PurchaseTableViewCell" owner:nil options:nil] lastObject];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backView.layer.shadowColor = [UIColor lightGrayColor].CGColor;
         cell.backView.layer.shadowOffset = CGSizeMake(0.5, 0.5);
         cell.backView.layer.shadowOpacity = YES;
        
        if (self.homeArr.count) {
            
            BorrowGetHome *model = self.homeArr[indexPath.row-2];
            [cell setDataWithModel:model];
        }
        
        
        if (indexPath.row == 2) {
            
            if (Screen_Width == 320) {
                cell.projectName.font = [UIFont systemFontOfSize:13.0f];
                cell.UntiDetail.font = [UIFont systemFontOfSize:10.0f];
            }
        }else
        {
            if (Screen_Width == 320) {
                cell.projectName.font = [UIFont systemFontOfSize:13.0f];
                cell.UntiDetail.font = [UIFont systemFontOfSize:10.0f];
                
            }

        }
        return cell;
    }
    

 
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        return 20 + Screen_Width/4;
    }else if(indexPath.row == 1){
        return 100;
    }else if (indexPath.row == self.homeArr.count+2){
        return 90;
    }
    
    return 200;
    
}



//tableView的点击事件
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    

    if (indexPath.row >1 && indexPath.row < self.homeArr.count + 2){
        
        CurrentViewController *currentView = [[CurrentViewController alloc] init];
        
        [UIView animateWithDuration:2 animations:^{
            if (self.homeArr.count) {
                BorrowGetHome *model = self.homeArr[indexPath.row-2];
                currentView.borrowId = model.BorrowId;
                currentView.num = @"123";
                currentView.item = [NSString stringWithFormat:@"%@%@",model.ProjectName ,model.Code];
                currentView.percentStr = [NSString stringWithFormat:@"%.2f",model.Proggress];

            }
            currentView.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:currentView animated:YES];
        }];
    }
    
}
//轮播接口
- (void)getSearchImage{
    
    //http://open.wanyuanfu.net/api/user/openapi  Image.GetSearchImage
    
    NSDictionary *para = @{@"ClassImage":@"1"};
    [NetWorkManager requestWithType:HttpRequestTypePost withMethodName:@"Image.GetSearchImage" withParaments:para withSuccessBlock:^(NSDictionary *object) {
        
        for (NSDictionary *dict in object[@"Data"]) {
            NSString *imageStr = dict[@"PicsmallImage"];
            [self.imageArray addObject:imageStr];
        }
        [_mytableView reloadData];
    } withFailureBlock:^(NSError *error) {
        
        
    } progress:nil];
    
}

//头部轮播视图
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    
    
    if (_imageArray.count) {

        NSMutableArray *urlarr = [NSMutableArray array];
        for (NSString *str in _imageArray) {
            NSURL *imurl = [NSURL URLWithString:str];
            [urlarr addObject:imurl];
        }
        UIImage *placeholder = [UIImage imageNamed:@"SHOUYE_02"];
        ZLScrolling *zl = [[ZLScrolling alloc] initWithCurrentController:self frame:CGRectMake(0, 0, Screen_Width, 200*[[UIScreen mainScreen] bounds].size.height / 736) photos:urlarr placeholderImage:placeholder];
        _zl = zl;
        _zl.timeInterval = 1;
        _zl.pageControl.pageIndicatorTintColor = [UIColor whiteColor];
        _zl.pageControl.currentPageIndicatorTintColor = [UIColor redColor];
        _zl.delegate= self;
        _zl.view.frame = CGRectMake(0, 0, Screen_Width, 200*[[UIScreen mainScreen] bounds].size.height / 736 );
    }else{
        NSArray *arr = @[@"SHOUYE_02"];
        ZLScrolling *zl = [[ZLScrolling alloc] initWithCurrentController:self frame:CGRectMake(0, 0, Screen_Width, 200*[[UIScreen mainScreen] bounds].size.height / 736 ) photos:arr placeholderImage:nil];
        _zl = zl;
        _zl.timeInterval = 1;
        _zl.pageControl.pageIndicatorTintColor = [UIColor redColor];
        _zl.delegate= self;
        _zl.view.frame = CGRectMake(0, 0, Screen_Width, 200*[[UIScreen mainScreen] bounds].size.height / 736 );

    }
    return _zl.view;
    
}


-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 200 *[[UIScreen mainScreen] bounds].size.height / 736;
}


-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.001;
}

#pragma mark ---------------tableView结束---------------

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.mytableView.mj_header beginRefreshing];
    
    [self.navigationController setNavigationBarHidden:YES animated:NO];
    UIView *statusBarView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, Screen_Width, 20)];
    statusBarView.backgroundColor=[UIColor colorWithRed:0.76 green:0.12 blue:0.18 alpha:1];
    [self.view addSubview:statusBarView];
    
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
    [_mytableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:1 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
    
    
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:NO];

}

//点击签到 调用[[UIApplication sharedApplication] keyWindow];
- (void)signIn{
    UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
    _window = window;
    [UIView  animateWithDuration:0.2 animations:^{
        _backView = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, Screen_Width, Screen_Height)];
        _backView.backgroundColor = [UIColor colorWithRed:0.16 green:0.17 blue:0.21 alpha:0.5];
        [window addSubview:_backView];
        
    }];
    
    [_backView addTarget:self action:@selector(touchUp) forControlEvents:UIControlEventTouchUpInside];
    
    UIView *sgnIn = [[UIView alloc] initWithFrame:CGRectMake(Screen_Width/2 - 115, Screen_Height/2 - 105, 230, 210)];
    [self QianDaoWithSum:_SumNumber];
    sgnIn.layer.cornerRadius = 5;
    sgnIn.layer.masksToBounds = YES;
    sgnIn.userInteractionEnabled = YES;
    if ([_State isEqualToString:@"1"]) {
        _State = @"1";
        if ([_SaleNumber isEqualToString:@"0"]) {
            [sgnIn addSubview:self.dailYCheckThirdV];
        } else {
            [sgnIn addSubview:self.dailYCheckSecondV];
        }
    } else {
        _State = @"0";
        [sgnIn addSubview:self.dailYCheckFirstV];
    }
    
    [_backView addSubview:sgnIn];
    
   
}

- (void)click:(UIButton *)btn {
    [self getDailyCheck];
    
    UIView *subview = [btn superview];
    UIView *view = [[btn superview] superview];
    self.overRequestBlock = ^void() {
        if ([_State isEqualToString:@"1"]) {
            [subview removeFromSuperview];
            [view addSubview:self.dailYCheckSecondV];
            return ;
        }else{
            NSString *loginId = [[NSUserDefaults standardUserDefaults] objectForKey:@"LoginId"];
            NSDictionary *para = @{
                                   @"LoginId":loginId
                                   };
            [NetWorkManager requestWithType:HttpRequestTypePost withMethodName:@"Api.GetNumber" withParaments:para withSuccessBlock:^(NSDictionary *object) {
                NSLog(@"%@",object);
                _SumNumber = [object[@"Data"] firstObject][@"SumNumber"];
                _State = [object[@"Data"] firstObject][@"Sate"];
                _SaleNumber = [object[@"Data"] firstObject][@"SaleNumber"];
                [subview removeFromSuperview];
                
                
                NSLog(@"%@-----%@",_SumNumber ,_SaleNumber);
                if ([_SaleNumber isEqualToString:@"0"]) {
                    self.dailYCheckSecondV.dailyNumLabel.text = [NSString stringWithFormat:@"%@", _SumNumber];
                    self.dailYCheckSecondV.remainsNumLabel.text = [NSString stringWithFormat:@"%@", _SaleNumber];
                    [view addSubview:self.dailYCheckThirdV];
                } else {
                    self.dailYCheckSecondV.dailyNumLabel.text = [NSString stringWithFormat:@"%@", _SumNumber];
                    self.dailYCheckSecondV.remainsNumLabel.text = [NSString stringWithFormat:@"%@", _SaleNumber];
                    [view addSubview:self.dailYCheckSecondV];
                }
                
            } withFailureBlock:^(NSError *error) {
                
                
                
            } progress:nil];
            
            
        }

    };
    

}

- (void)checkBtnClick:(UIButton *)btn {
    
    UIView *subview = [btn superview];
    [subview removeFromSuperview];
    [_backView removeFromSuperview];
    
    MyInvestViewController *investView =[[MyInvestViewController alloc] init];
    [self setHidesBottomBarWhenPushed:YES];
    investView.num = 6;
    [self.navigationController pushViewController:investView animated:YES];
    [self setHidesBottomBarWhenPushed:NO];
}

//释放windows
- (void)clickSureBtn:(UIButton *)tap{
    
    
    [_backView removeFromSuperview];
    
}
//释放windows
- (void)touchUp{
    
    [_backView removeFromSuperview];
    
}

//获取定期
- (void)getHome{
    
//    http://test.open.wanyuanfu.net/api/user/openapi
    
    NSDictionary *para = @{};
    [NetWorkManager requestWithType:HttpRequestTypePost withMethodName:@"Borrow.GetHome" withParaments:para withSuccessBlock:^(NSDictionary *object) {
        [self.homeArr removeAllObjects];
           [self.mytableView.mj_header endRefreshing];
        for (NSDictionary *dic in object[@"Data"]) {
           BorrowGetHome *homeModel = [BorrowGetHome mj_objectWithKeyValues:dic];
        
            [self.homeArr addObject:homeModel];

        }
        [_mytableView reloadData];
        
    } withFailureBlock:^(NSError *error) {
        
           [self.mytableView.mj_header endRefreshing];
    } progress:nil];
}

//获取累计投资金额
-(void)getHomeAmount{
    
    NSDictionary *para = @{};
    [NetWorkManager requestWithType:HttpRequestTypePost withMethodName:@"Invest.GetHomeAmount" withParaments:para withSuccessBlock:^(NSDictionary *object) {
        
        NSDictionary *dict = [object[@"Data"] firstObject];
        BorrowGetHome *homeModel = [BorrowGetHome mj_objectWithKeyValues:dict];
        [_moneyArr addObject:homeModel];
    } withFailureBlock:^(NSError *error) {
        NSLog(@"%@",error);
        
    } progress:nil];
}



//MJ刷新
-(void)refresh
{
    MJRefreshNormalHeader  *header = [MJRefreshNormalHeader  headerWithRefreshingTarget:self refreshingAction:@selector(getHome)];
    [self getSearchImage];
    [self getHomeAmount];
    header.stateLabel.hidden = YES;
//    [header setTitle:@"1" forState:MJRefreshStateIdle];
//    
//    [header setTitle:@"2" forState:MJRefreshStatePulling];
//    
//    [header setTitle:@"3" forState:MJRefreshStateRefreshing];
 
    
    self.mytableView.mj_header = header;
    //下拉刷新
//    self.mytableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^
//                                  {
//                                      
//                                      [self getHome];
//                                      
//                                      [self.mytableView.mj_header endRefreshing];
//                                  }];
//    
}


//每日签到
-(void)getDailyCheck{
    
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"LoginId"] isEqualToString:@""]) {
        WelcomeLoginViewController *loginView = [[WelcomeLoginViewController alloc] init];
        loginView.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:loginView animated:NO];
        
    }else{
        
        NSString *loginId = [[NSUserDefaults standardUserDefaults] objectForKey:@"LoginId"];
        NSDictionary *para = @{
                               @"LoginId":loginId
                               };
        
        [NetWorkManager requestWithType:HttpRequestTypePost withMethodName:@"Api.GetDailyCheck" withParaments:para withSuccessBlock:^(NSDictionary *object) {
            NSLog(@"----%@",object);
            if ([object[@"Code"] isEqualToString:@"00000"]) {
                
                [ToastView showInfoWithStatus:[object[@"Data"] firstObject][@"Message"]];
                if ([[object[@"Data"] firstObject][@"Message"] isEqualToString:@"今日已签到"]) {
                    return ;
                }else{
                    
                [self QianDaoWithSum:[NSString stringWithFormat:@"%ld",[_SumNumber integerValue]]];
                    if (self.overRequestBlock) {
                        self.overRequestBlock();
                    }
                }
                
            }else{
                [ToastView showInfoWithStatus:object[@"Message"]];
            }
            
        } withFailureBlock:^(NSError *error) {
            NSLog(@"%@",error);
            
        } progress:nil];

    }
    
}

- (NSArray *)determineTheNumber:(NSInteger)num {
    if (num >= 0 && num < 10) {
        return @[@"0",[NSString stringWithFormat:@"%ld", num]];
    } else {
        return @[[NSString stringWithFormat:@"%ld", num / 10], [NSString stringWithFormat:@"%ld", num % 10]];
    }
}


-(void)getNumber{
    
    NSString *loginId = [[NSUserDefaults standardUserDefaults] objectForKey:@"LoginId"];
    
    if (loginId) {
        NSDictionary *para = @{
                               @"LoginId":loginId
                               };
        [NetWorkManager requestWithType:HttpRequestTypePost withMethodName:@"Api.GetNumber" withParaments:para withSuccessBlock:^(NSDictionary *object) {
            NSLog(@"%@",object);
            _SumNumber = [object[@"Data"] firstObject][@"SumNumber"];
            _State = [object[@"Data"] firstObject][@"Sate"];
            _SaleNumber = [object[@"Data"] firstObject][@"SaleNumber"];
            [self signIn];
            
        } withFailureBlock:^(NSError *error) {
            NSLog(@"%@", error);
            
        } progress:nil];
    } else {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"未登录，请先登录" delegate: self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        alert.tag = 10000;
        [alert show];
    }
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (alertView.tag == 10000 && buttonIndex == 1) {
        WelcomeLoginViewController *loginView = [[WelcomeLoginViewController alloc] init];
        loginView.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:loginView animated:NO];
    }
}

//
- (void)QianDaoWithSum:(NSString *)num{
    if (num.length == 1) {
        
        self.dailYCheckFirstV.firstNumImageV.image = [UIImage imageNamed:@"number0"];
        self.dailYCheckFirstV.secondNumImageV.image = [UIImage imageNamed:[NSString stringWithFormat:@"number%@",num]];
    }else if (num.length == 2){
        NSString *first = [num substringToIndex:1];
        NSString *second = [num substringFromIndex:1];
        
        self.dailYCheckFirstV.firstNumImageV.image = [UIImage imageNamed:[NSString stringWithFormat:@"number%@",first]];
        self.dailYCheckFirstV.secondNumImageV.image = [UIImage imageNamed:[NSString stringWithFormat:@"number%@",second]];
        
        
    }
    
}


@end

